package com.ssyc.gsk_teacher.activity;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.ssyc.common.base.BaseActivity;
import com.ssyc.common.utils.UIHelper;
import com.ssyc.gsk_teacher.R;

/**
 * 教师端--教学与反思--我的思考
 * Created by Kevin on 2018/6/25
 */

public class TeacherMyFansiActivity extends BaseActivity implements View.OnClickListener {

    //返回键
    private ImageView ivBack;

    //gradeID
    private String gradeId;

    private String lessonId;

    private String classId;

    //保存按钮
    private ImageView iv_save;

    //输入框
    private EditText et_content;

    //字数
    private TextView tvNum;

    @Override
    protected boolean isNeedShowTitle() {
        return false;
    }

    @Override
    protected String setTitleText() {
        return null;
    }

    @Override
    protected int getContentLayout() {
        return R.layout.teacher_activity_my_fansi;
    }

    @Override
    protected void init() {

        showContent();

        //初始化视图
        initView();

        //接收数据
        InitIntent();

        initListener();
    }


    /**
     * 设置输入监听
     */
    private void initListener() {
        //设置输入监听
        et_content.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                String content = et_content.getText().toString().trim();
                if (TextUtils.isEmpty(content)) {
                    tvNum.setText("0/500");
                } else {
                    if (content.length() > 500) {
                        UIHelper.showToast(TeacherMyFansiActivity.this, "最多只能输入500字");
                        return;
                    } else {
                        tvNum.setText(content.length() + "/500");
                    }
                }
            }
        });
    }

    /**
     * 接收数据
     */
    private void InitIntent() {
        gradeId = getIntent().getStringExtra("gradeId");
        lessonId = getIntent().getStringExtra("lessonId");
        classId = getIntent().getStringExtra("classId");
    }

    /**
     * 初始化视图的方法
     */
    public void initView() {
        ivBack = findViewById(R.id.iv_back);
        ivBack.setOnClickListener(this);
        iv_save = findViewById(R.id.iv_save);
        iv_save.setOnClickListener(this);

        et_content = findViewById(R.id.et_content);
        tvNum = findViewById(R.id.tv_num);

    }


    /**
     * 点击事件
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.iv_back) {
            finish();
        } else if (id == R.id.iv_save) {
            //保存
            String content = et_content.getText().toString().trim();
            if(TextUtils.isEmpty(content)){
                UIHelper.showToast(this,"输入内容为空");
            }else{
                //提交

                UIHelper.showToast(this,content);
            }

        }
    }
}
